<template>
  <li class="todo-item">
    <label>
      <input type="checkbox" v-model="isCheck"/>
      <span :class="{done: todo.completed}">{{todo.title}}</span>
    </label>
    <button class="btn btn-danger" @click="deleteTodo(todo.id)">删除</button>
  </li>
</template>

<script>
export default {
  name: 'TodoItem',
  props: {
    todo: Object,
    deleteTodo: Function,
    toggleTodo: Function,
  },

  computed: {
    // 是否勾选
    isCheck: {
      get () {
        return this.todo.completed
      },
      set(value) {
        // this.todo.completed = value
        this.toggleTodo(this.todo)
      }
    }
  }
}
</script>

<style scoped>
.todo-item {
  list-style: none;
  height: 36px;
  line-height: 36px;
  padding: 0 5px;
  border-bottom: 1px solid #ddd;
}

.todo-item label {
  float: left;
  cursor: pointer;
}

.todo-item label input {
  vertical-align: middle;
  margin-right: 6px;
  position: relative;
  top: -1px;
}

.todo-item button {
  float: right;
  margin-top: 3px;
}

.todo-item:last-child {
  border-bottom: none;
}
.todo-item .done {
  color: #666;
  text-decoration: line-through;
}

</style>
